﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script type="text/javascript">
        $(document).ready(function() {
            var urlPar = myUtils.urlDecode(location.href);
            var cUrlPar = myUtils.urlDecode(unescape(urlPar.content));
            $.ajax({
                url: "Service.asmx/CallService1",
                type: "POST",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify({ skey: "module", model: myUtils.format("{ID:'{0}'}", cUrlPar.mid) }),
                success: function(data) {
                    data = JSON.parse(data.d);
                    var content = '';
                    $(data).each(function() {
                        content += '<div class="left">' +
                                        '<h2 title="{0}">{1}</h2>' +
                                        '<div id="{2}{3}"></div>' +
                                    '</div>';
                        content = myUtils.format(content, this.Detail, this.Name, this.Code, this.ID);
                    });
                    content += '<div style="clear: both;"></div>';
                    $("#left").html(content);
                    $(data).each(function() {
                        AppendItemInfo(this.ID, this.Code, cUrlPar.id);
                    });
                },
                error: function(x, e) {
                    $("#left").html(x.responseText);
                }
            });
        });

        function AppendItemInfo(id, code, rightId) {
            $.ajax({
                url: "Service.asmx/CallService1",
                type: "POST",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify({ skey: "item", model: myUtils.format("{MID:'{0}'}", id) }),
                success: function(data) {
                    data = JSON.parse(data.d);
                    var content = '';
                    content += '<ul>';
                    $(data).each(function(i) {
                        var cUrl = escape(myUtils.format("detail.htm?mid={0}&id={1}", this.MID, this.ID));
                        var url = myUtils.format("index.htm?content={0}", cUrl);
                        content += myUtils.format('<li><a href="javascript:AppendItemDetailInfo({0});">{1}</a></li>', this.ID, this.Title);
                        if (rightId == undefined) {
                            if (i == 0) {
                                AppendItemDetailInfo(this.ID);
                            }
                        }
                        else {
                            AppendItemDetailInfo(rightId);
                        }
                    });
                    content += '</ul>';
                    $("#" + code + id).html(content);
                },
                error: function(x, e) {
                    $("#" + code + id).html(x.responseText);
                }
            });
        }

        function AppendItemDetailInfo(id) {
            $.ajax({
                url: "Service.asmx/CallService1",
                type: "POST",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify({ skey: "item", model: myUtils.format("{ID:'{0}'}", id) }),
                success: function(data) {
                    data = JSON.parse(data.d);
                    data = data[0];
                    var content = '<div class="right">' +
                                    '<h2><a href="#">{0}</a></h2>' +
                                    '<div class="articles">{1}</div>' +
                                  '</div>';
                    content = myUtils.format(content, data.Title, data.Body);
                    $("#right").html(content);
                },
                error: function(x, e) {
                    $("#right").html(x.responseText);
                }
            });
        }
    </script>

</head>
<body>
    <div id="right">
    </div>
    <div id="left">
    </div>
    <div style="clear: both;">
    </div>
</body>
</html>
